home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Folder・Icon・Opener 1.0.1.sit / Folder•Icon•Opener 1.0.1 / source code / sources / FIOpen.dialog.c < prev    next >
Text File  |  1996-05-05  |  9KB  |  356 lines

  1. /*
  2.  *--------------------------------------------------------------
  3.  * FIOpen.dialog.c
  4.  *--------------------------------------------------------------
  5.  *    Copyright ゥ Fumio Rokkaku, 1996
  6.  *--------------------------------------------------------------
  7.  */
  8. #pragma once
  9.  
  10. /* System Headers */
  11. #include <QuickDraw.h>
  12. #include <Windows.h>
  13. #include <Dialogs.h>
  14. #include <Controls.h>
  15. #include <Palettes.h>
  16. #include <OSUtils.h>
  17. #include <Icons.h>
  18. #include <Gestalt.h>
  19. #include <Errors.h>
  20.  
  21. /* Project Headers */
  22. #include "FIOpen.h"
  23.  
  24. /*
  25.  *--------------------------------------------------------------
  26.  *    dialog and alert IDs
  27.  *--------------------------------------------------------------
  28.  */
  29. enum constDialogIDs {
  30.     kAboutDialogID    = 128,
  31.     kCopyDialogID,
  32.     kNoIconAlertID    = 2000,
  33.     kNoFolderAlertID,
  34.     kNoEditorAlertID,
  35.     kAEErrorAlertID
  36. };
  37.  
  38. /*
  39.  *--------------------------------------------------------------
  40.  *    globals
  41.  *--------------------------------------------------------------
  42.  */
  43. static DialogRef    gAboutDialog = nil;
  44. static DialogRef    gCopyDialog = nil;
  45.  
  46. /*
  47.  *--------------------------------------------------------------
  48.  *    fuction prototypes used within this source
  49.  *--------------------------------------------------------------
  50.  */
  51. static short DoModelessDlgKeyDown(EventRecord *);
  52.  
  53. /*
  54.  *--------------------------------------------------------------
  55.  *    DoDialogs
  56.  *--------------------------------------------------------------
  57.  *    handle modeless dialog events
  58.  *--------------------------------------------------------------
  59.  */
  60. void DoDialogs(EventRecord *theEvent)
  61. {
  62.     DialogRef    aDialog = (DialogRef)(theEvent->message);
  63.     short        itemHit = -1;
  64.  
  65.     switch(theEvent->what) {
  66.     case keyDown:
  67.     case autoKey:
  68.         itemHit = DoModelessDlgKeyDown(theEvent);
  69.         if (itemHit >= ok) {
  70.             return;
  71.         }
  72.         break;
  73.     case updateEvt:
  74.         switch (GetWRefCon(GetDialogWindow(aDialog))) {
  75.         case kAboutType:
  76.             DrawAboutDialog();
  77.             break;
  78.         }
  79.         break;
  80.     case diskEvt:
  81.         DoMountDisk(theEvent);
  82.         break;
  83.     case   osEvt:
  84.         DoOSEvent(theEvent);
  85.         break;
  86.     }
  87.  
  88.     if (DialogSelect(theEvent, &aDialog, &itemHit)) {
  89.         switch (GetWRefCon(GetDialogWindow(aDialog))) {
  90.         case kAboutType:
  91.             DoAboutDialog(itemHit);
  92.             break;
  93.         }
  94.     }
  95. }
  96. /*
  97.  *--------------------------------------------------------------
  98.  * DoModelessDlgKeyDown
  99.  *--------------------------------------------------------------
  100.  *    handle key events in modeless dialog
  101.  *--------------------------------------------------------------
  102.  */
  103. static short DoModelessDlgKeyDown(EventRecord *theEvent)
  104. {
  105.     int        aCharCode = (theEvent->message & charCodeMask);
  106.     short    itemHit = -1;
  107.  
  108.     if (theEvent->modifiers & cmdKey) {
  109.         if (aCharCode == '.')  {
  110.             itemHit = cancel;
  111.         } else {
  112.             DoMenus(MenuKey(aCharCode));
  113.             return (-1);    /* bogus value */
  114.         }
  115.     }
  116.     else switch (aCharCode) {
  117.     case kEnterKey:
  118.     case kReturnKey:
  119.         itemHit = ok;
  120.         break;
  121.     case kEscapeKey:
  122.         itemHit = cancel;
  123.         break;
  124.     }
  125.  
  126.     if (itemHit >= ok) {
  127.         switch (GetWRefCon(FrontWindow())) {
  128.         case kAboutType:
  129.             DoAboutDialog(itemHit);
  130.             break;
  131.         }
  132.     }
  133.     return (itemHit);
  134. }
  135. /*
  136.  *--------------------------------------------------------------
  137.  * OpenAboutDialog
  138.  *--------------------------------------------------------------
  139.  *    show about dialog
  140.  *--------------------------------------------------------------
  141.  */
  142. void OpenAboutDialog(void)
  143. {
  144.     if (gAboutDialog == nil) {
  145.         gAboutDialog = GetNewDialog(kAboutDialogID, (WindowRef)0, (WindowRef)-1);
  146.     }
  147.     if (gAboutDialog != nil) {
  148.  
  149.         WindowRef    aWindow = GetDialogWindow(gAboutDialog);
  150.         GrafPtr    savePort;
  151.  
  152.         GetPort(&savePort);
  153.         SetPortWindowPort(aWindow);
  154.  
  155.         TextFont(applFont);
  156.         TextSize(9);
  157.         TextMode(srcCopy);
  158.         SetWRefCon(aWindow, kAboutType);
  159.  
  160.         ShowWindow(aWindow);
  161.         SelectWindow(aWindow);
  162.         SetPort(savePort);
  163.     }
  164. }
  165. /*
  166.  *--------------------------------------------------------------
  167.  * DoAboutDialog
  168.  *--------------------------------------------------------------
  169.  *    handle the about dialog events
  170.  *--------------------------------------------------------------
  171.  */
  172. void DoAboutDialog(const short theItem)
  173. {
  174.     if (gAboutDialog != nil) {
  175.         switch (theItem) {
  176.         case ok:
  177.             if (StillDown()) {
  178.                 /* give working chance to backgound tasks */
  179.                 do {
  180.                     EventRecord    anEvent;
  181.                     WaitNextEvent(mUpMask, &anEvent, -1, nil);
  182.                 } while (WaitMouseUp());
  183.             }
  184.             DisposeDialog(gAboutDialog);
  185.             gAboutDialog = nil;
  186.             break;
  187.         }
  188.     }
  189. }
  190. /*
  191.  *--------------------------------------------------------------
  192.  * DrawAboutDialog
  193.  *--------------------------------------------------------------
  194.  *    handle the about update events
  195.  *--------------------------------------------------------------
  196.  */
  197. void DrawAboutDialog(void)
  198. {
  199.     GrafPtr    savePort;
  200.     GrafPtr    thisPort = (GrafPtr)GetWindowPort(GetDialogWindow(gAboutDialog));
  201.  
  202.     GetPort(&savePort);
  203.     SetPort(thisPort);
  204.     RaisedRect(&thisPort->portRect);
  205.     SetPort(savePort);
  206. }
  207. /*
  208.  *--------------------------------------------------------------
  209.  * CloseAboutDialog
  210.  *--------------------------------------------------------------
  211.  *    make the about dialog disappear
  212.  *--------------------------------------------------------------
  213.  */
  214. void CloseAboutDialog(void)
  215. {
  216.     if (gAboutDialog != nil) {
  217.         DisposeDialog(gAboutDialog);
  218.         gAboutDialog = nil;
  219.     }
  220. }
  221. /*
  222.  *--------------------------------------------------------------
  223.  * IsAboutDialog
  224.  *--------------------------------------------------------------
  225.  *    make the about dialog go away
  226.  *--------------------------------------------------------------
  227.  */
  228. Boolean IsAboutDialog(void)
  229. {
  230.     return (
  231.         (gAboutDialog != nil)
  232.      && (FrontWindow() == GetDialogWindow(gAboutDialog))
  233.     );
  234. }
  235. /*
  236.  *--------------------------------------------------------------
  237.  * OpenCopyingDialog
  238.  *--------------------------------------------------------------
  239.  *    make copying dialog appear
  240.  *--------------------------------------------------------------
  241.  */
  242. void OpenCopyingDialog(void)
  243. {
  244.     if (gAboutDialog == nil) {
  245.         gCopyDialog = GetNewDialog(kCopyDialogID, (WindowRef)0, (WindowRef)-1);
  246.     }
  247.     if (gCopyDialog != nil) {
  248.         WindowRef    aWindow = GetDialogWindow(gCopyDialog);
  249.         if (IsWindowVisible(aWindow) == false) {
  250.             GrafPtr        thisPort = (GrafPtr)GetWindowPort(aWindow);
  251.             GrafPtr        savePort;
  252.  
  253.             GetPort(&savePort);
  254.             SetPort(thisPort);
  255.             ShowWindow(aWindow);
  256.             SelectWindow(aWindow);
  257.             DrawDialog(gCopyDialog);
  258.             ValidRect(&thisPort->portRect);
  259.             SetPort(savePort);
  260.         }
  261.     }
  262. }
  263. /*
  264.  *--------------------------------------------------------------
  265.  * ShowCopyingIcon
  266.  *--------------------------------------------------------------
  267.  *    make copying dialog appear
  268.  *--------------------------------------------------------------
  269.  */
  270. void ShowCopyingIcon(Handle theSuite)
  271. {
  272.     if (gCopyDialog != nil) {
  273.         WindowRef    aWindow = GetDialogWindow(gCopyDialog);
  274.  
  275.         if (FrontWindow() != aWindow) {
  276.             SelectWindow(aWindow);
  277.         }
  278.         if (theSuite != nil) {
  279.             GrafPtr    savePort;
  280.             Rect    aRect;
  281.             Handle    aHandle;
  282.             short    aType;
  283.  
  284.             GetPort(&savePort);
  285.             SetPortWindowPort(aWindow);
  286.             DrawDialog(gCopyDialog);
  287.  
  288.             GetDialogItem(gCopyDialog, 1, &aType, &aHandle, &aRect);
  289.             EraseRect(&aRect);
  290.             PlotIconSuite(&aRect, kAlignNone, kTransformNone, theSuite);
  291.             SetPort(savePort);
  292.         }
  293.     }
  294. }
  295. /*
  296.  *--------------------------------------------------------------
  297.  * CloseCopyingDialog
  298.  *--------------------------------------------------------------
  299.  *    make copying dialog disappear
  300.  *--------------------------------------------------------------
  301.  */
  302. void CloseCopyingDialog(void)
  303. {
  304.     if (gCopyDialog != nil) {
  305.         DisposeDialog(gCopyDialog);
  306.         gCopyDialog = nil;
  307.     }
  308. }
  309. /*
  310.  *--------------------------------------------------------------
  311.  * NoIconAlert
  312.  *--------------------------------------------------------------
  313.  *    alert message which tells the folder has no custom icon
  314.  *--------------------------------------------------------------
  315.  */
  316. void NoIconAlert(const StringPtr theFolderName)
  317. {
  318.     ParamText(theFolderName, nil, nil, nil);
  319.     StopAlert(kNoIconAlertID, nil);
  320. }
  321. /*
  322.  *--------------------------------------------------------------
  323.  * NoFolderAlert
  324.  *--------------------------------------------------------------
  325.  *    alert message which tells the spec is not a folder
  326.  *--------------------------------------------------------------
  327.  */
  328. void NoFolderAlert(const StringPtr theFileName)
  329. {
  330.     ParamText(theFileName, nil, nil, nil);
  331.     StopAlert(kNoFolderAlertID, nil);
  332. }
  333. /*
  334.  *--------------------------------------------------------------
  335.  * NoEditorAlert
  336.  *--------------------------------------------------------------
  337.  *    alert message which tells no application was found
  338.  *--------------------------------------------------------------
  339.  */
  340. void NoEditorAlert(void)
  341. {
  342.     StopAlert(kNoEditorAlertID, nil);
  343. }
  344. /*
  345.  *--------------------------------------------------------------
  346.  * AEErrorAlert
  347.  *--------------------------------------------------------------
  348.  *    alert message which tells some AppleEvent error occurred
  349.  *--------------------------------------------------------------
  350.  */
  351. void AEErrorAlert(const StringPtr theFileName)
  352. {
  353.     ParamText(theFileName, nil, nil, nil);
  354.     CautionAlert(kAEErrorAlertID, nil);
  355. }
  356.